<template>
    <h2>用户添加理财</h2>

    <table class="table table-bordered">
       <tr>
            <td>理财名称</td>
            <td>{{ state.F_Name }}</td>
       </tr>
       <tr>
            <td>年收益</td>
            <td>{{ state.F_Year }}</td>
       </tr>
       <tr>
            <td>利息</td>
            <td>
              <select v-model="state.I_Id">
                <option v-for="item in llist" :value="item.I_Id">{{ item.I_Name }}</option>
              </select>
            </td>
       </tr>
       <tr>
            <td>最低金额</td>
            <td>{{ state.F_MinMoney }}</td>
       </tr>
       <tr>
            <td>投资金额</td>
            <td><input type="text" v-model="UF_Money" />CNY</td>
       </tr>
       <tr>
            <td></td>
            <td><input type="button" value="添加" @click="add" /></td>
       </tr>
    </table>

</template>

<script setup lang="ts">
import {ref, reactive, onMounted,toRefs} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import {useStore} from '../../store/user'
const useStores=useStore();
import axios from 'axios';
const router=useRouter();
const route=useRoute();
const data:any=reactive({
    state:{
       
    },
    ListCount:'',
    PageCount:'',
    UF_Money:'',
    list:[],
    llist:[]
})
let {state,list,ListCount,PageCount,llist,UF_Money} =toRefs(data);
onMounted(()=>{
  show();
  bang();
})

//8.	管理员-理财列表分页展示
const show=()=>{
    axios({
        url:"/api/Finance/SelById",
        method:'get',
        params:{
            fid:route.query.id
        }
    })
    .then(res=>{
        console.log(res);
        state.value=res.data.data[0];
    })
}
//6.	理财利息从数据库读取下拉列表展示
const bang=()=>{
    axios({
        url:"/api/Finance/SelInterest",
        method:'get',
    })
    .then(res=>{
        console.log(res);
        llist.value=res.data.data;
    })
}

const add=()=>{
    //5.	用户-添加理财金额不能低于最低金额（5分）
    if(UF_Money.value<state.value.F_MinMoney)
    {
        alert("用户-添加理财金额不能低于最低金额");
        return;
    }
    axios({
        url:"/api/Finance/PostAddFinance",
        method:'post',
        data:{
            U_Id:useStores.userInfo.U_Id,
            F_Id:route.query.id,
            UF_Money:UF_Money.value
           
        }
    })
    .then(res=>{
        console.log(res);
        if(res.data.data>0)
        {
            alert("添加成功");
            router.push('/userFinanceList');
        }
        else
        {
            alert("添加失败");
            return;
        }
    })
}
</script>


<style>


</style>